//
// Created by Administrator on 2024/3/25.
//
#include<bits/stdc++.h>

using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<vector<int>> a(n, vector<int>(n, 0));//用Vector定义可伸缩的二维数组
        for (int i = 0; i < n; i++)
            for (int j = 0; j <= i; j++)cin >> a[i][j];
        vector<vector<int>> dp(n, vector<int>(n, 0));//用Vector定义可伸缩的二维数组，也可以压缩成一维数组

        for (int j = 0; j < n; j++) {
            dp[n - 1][j] = a[n - 1][j];
        }
        for (int i = n - 2; i >= 0; i--) {
            for (int j = 0; j <= i; j++) {
                dp[i][j] = max(dp[i + 1][j], dp[i + 1][j + 1]) + a[i][j];
            }
        }
        cout << dp[0][0] << endl;

    }

    return 0;
}